package com.exception;

import com.util.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.context.request.WebRequest;
import com.web.Result;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class ExceptionHandler {

    private Logger log = LoggerFactory.getLogger(ExceptionHandler.class);

    @org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
    @ResponseBody
    public Result commonExceptionHandler(Exception e, HttpServletRequest request){
        //不能获取请求体 以后解决
        log.error("请求url:【{}】发生异常，异常参数：【{}】,异常原因：【{}】", request.getRequestURI(), JsonUtils.mapToJson(request.getParameterMap()), e.getMessage());
        return Result.failure("服务器发生异常！请联系管理员", null);
    }
}
